package cn.wolfcode.chatroom.controller;

import cn.wolfcode.chatroom.core.SessionContext;
import cn.wolfcode.chatroom.core.domain.ChatroomMessage;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/message")
public class MessageController {

    @RequestMapping("/send")
    public String send(HttpServletRequest request, String username, String msg) {
        System.out.println("ip:" + request.getRemoteAddr());
        ChatroomMessage message = new ChatroomMessage();
        message.setSender(username);
        message.setContent(msg);
        message.setType(ChatroomMessage.NORMAL);

        SessionContext.sendMsg(message);
        return "success";
    }
}
